package drops.control;

import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.LinkedList;
import java.util.List;

import org.apache.torque.om.ObjectKey;
import org.apache.torque.util.Criteria;

import drops.dao.DentalTransaction;
import drops.dao.DentalTransactionPeer;
import drops.dao.Patient;

public class DentalTransactionControl {
	
	public static int addDentalTransaction(int patientNumber, Date date, String description, double debit, Date creditDate, double creditAmount, double balance){
		if (validateTransaction(patientNumber, date, description, debit, creditDate, creditAmount, balance)) {
			int key = DentalTransactionPeer.addDentalTransaction(patientNumber, date, description, debit, creditDate, creditAmount, balance);
			return key;
		}
	return -1;
	}
	public static void deleteDentalTransaction(int transactionNumber) {
		DentalTransactionPeer.deleteDentalTransaction(transactionNumber);
	}
	public static DentalTransaction searchTransactionByTransactionNumber(int transactionNumber){
		return DentalTransactionPeer.searchTransactionByTransactionNumber(transactionNumber);
	}
	
	public static List <DentalTransaction> searchTransaction(String input, String category) {
		if (category=="Patient Number") {
			return searchTransactionByPatientNumber(Integer.parseInt(input));
		}
		else if (category=="Description") {
			return searchTransactionByDescription(input);
		}
		else if (category=="Transaction Number") {
			List <DentalTransaction> tList = new LinkedList <DentalTransaction> ();
			DentalTransaction t;
			t = searchTransactionByTransactionNumber(Integer.parseInt(input));
			if (t!=null) {
				tList.add(t);
			}
			return tList;
		}
		return null;
	}
	
	
	
	public static List<DentalTransaction> searchTransactionByPatientNumber(int patientNumber){
		return DentalTransactionPeer.searchTransactionByPatientNumber(patientNumber);
	}
	
	public static List<DentalTransaction> searchTransactionByDate(Date date) {
		return DentalTransactionPeer.searchTransactionByDate(date);
	}
	
	public static List<DentalTransaction> searchTransactionByDescription(String description) {
		return DentalTransactionPeer.searchTransactionByDescription(description);
	}
	
	private static boolean validateTransaction(int patientNumber, Date date, String description, double debit, Date creditDate, double creditAmount, double balance) {
		return true;
	}
}
